package cn.bulgat.spring.web;

import cn.bulgat.common.id.IIdGenerator;
import cn.bulgat.common.id.snowflake.SnowFlakeFactory;
import cn.bulgat.common.id.snowflake.SnowFlakeIdGenerator;
import cn.bulgat.common.id.snowflake.SnowFlakeLoader;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.MDC;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * 主类（项目启动入口）
 *
 */
// todo 如需开启 Redis，须移除 exclude 中的内容
@SpringBootApplication(exclude = {RedisAutoConfiguration.class})
@MapperScan("cn.bulgat.spring.web.mapper")
@EnableScheduling
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
public class Application {

    public static void main(String[] args) {
        Long dataCenterId = SnowFlakeLoader.getDataCenterId();
        Long machineId = SnowFlakeLoader.getMachineId();
        IIdGenerator<Long> idGenerator = SnowFlakeFactory.getSnowFlakeIdGenerator(dataCenterId, machineId);
        MDC.put("globalLogId", String.valueOf(idGenerator.nextId()));
        SpringApplication.run(Application.class, args);
    }

}
